package com.vincent.kdp.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.vincent.kdp.R;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.ui.notice.repository.NoticeRepository;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NoticeDetailsActivity extends AppCompatActivity {

    @Bind(R.id.back_img)
    ImageView mBackImg;
    @Bind(R.id.toolbar_center_tv)
    TextView mToolbarCenterTv;
    @Bind(R.id.content)
    WebView webView;

    NoticeRepository req=new NoticeRepository();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice_details);
        ButterKnife.bind(this);
        //获得富文本
        String title=getIntent().getStringExtra("title");
        String content=getIntent().getStringExtra("content");
        String newId=getIntent().getStringExtra("agentId");

        initData(newId);


        //contentTv.setText(Html.fromHtml(content));
        Log.i("Web",content);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webSettings.setAllowFileAccess(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setTextSize(WebSettings.TextSize.LARGER);

        webView.getSettings().setDefaultTextEncodingName("utf-8") ;
        webView.loadData(content, "text/html; charset=UTF-8",null);

        mToolbarCenterTv.setText(title);
    }

    private void initData(String newId) {
        Log.i("Web","-----"+newId);
        req.reqGetNotice(newId, new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {

            }

            @Override
            public void onFalse(String msg) {

            }
        });

    }

    @OnClick(R.id.back_img)
    public void onClick() {
        this.finish();
        overridePendingTransition(com.vincent.baseapp.R.anim.fragment_left_in, com.vincent.baseapp.R.anim.fragment_right_out);
    }

}
